﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dac.DAL.Repositories;
using Dac.Entities;

namespace Dac
{
    public partial class ProductDetail : System.Web.UI.Page
    {
        private string Lang
        {
            get
            {
                string lang = string.Empty;
                if (!string.IsNullOrEmpty(Request.QueryString["lang"]))
                    lang = Request.QueryString["lang"];
                return lang;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ProductId == -1)
                return;

            Product good = null;
            using (var repo = RepositoryFactory.ResolveRepository<ProductRepository>())
            {
                good = repo.Find(ProductId);
            }

            if (good != null && Lang == string.Empty)
            {
                imgPicture.ImageUrl = ProductPathUrl + good.ProductId.ToString() + "/" + good.PreviewImage;
                linkImage.NavigateUrl = ProductPathUrl + good.ProductId.ToString() + "/" + good.MainImage;
                lbTitle.Text = good.ProductNameRu;
                lbDescription.Text = good.ProductDescRu;
                //lbPriceName.Text = "Цена: ";
                //lbPrice.Text = good.Price.ToString();
                //lbStockName.Text = "Статус: ";
                //lbStock.Text = good.OutStock ? "Сток" : "Не сток";
            }
            else if (good != null && Lang == "eng")
            {
                imgPicture.ImageUrl = ProductPathUrl + good.ProductId.ToString() + "/" + good.PreviewImage;
                linkImage.NavigateUrl = ProductPathUrl + good.ProductId.ToString() + "/" + good.MainImage;
                lbTitle.Text = good.ProductNameEn;
                lbDescription.Text = good.ProductDescEn;
                //lbPriceName.Text = "Price: ";
                //lbPrice.Text = good.Price.ToString();
                //lbStockName.Text = "Status: ";
                //lbStock.Text = good.OutStock ? "In Stock" : "Not in Stock";
            }
        }

        public int ProductId
        {
            get
            {
                int result = -1;
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                    result = Convert.ToInt32(Request.QueryString["id"]);
                return result;
            }
        }
        private string ProductPathUrl
        {
            get
            {
                return ResolveClientUrl("~/Files/Products/");
            }
        }
    }
}